package first.forHuaWei.贪心;

import java.util.Arrays;

/**
 * @ClassName LC179
 * @description:
 * @author: 荣燊
 * @create: 2021-09-06 13:16
 **/
public class LC179 {
    // 数组中的数字能组合成的最大数
//    输入：nums = [10,2]
//    输出："210"
    public static void main(String[] args) {

    }

    // 这里的lamada表达式是为什么啊
    public static String largestNumber(int[] nums) {
        int n = nums.length;
        Integer[] integers = new Integer[n];
        for (int i=0; i<n; i++) {
            integers[i] = nums[i];
        }

        Arrays.sort(integers, (x, y)->{
            long sx = 10, sy = 10;
            while (sx <= x) {
                sx *= 10;
            }
            while (sy <= y) {
                sy *= 10;
            }
            return (int) (-sy*x - y + sx*y + x);
        });
       if (integers[0] == 0) {
           return "0";
       }
        StringBuffer stringBuffer = new StringBuffer();
        for (int num : integers) {
           stringBuffer.append(num);
       }
        return stringBuffer.toString();
    }
}
